﻿<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register TagPrefix="Club" TagName="WebContent" Src="~/UserControls/WebContent.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="ClubStarterKit.Data" %>
<%@ Import Namespace="SubSonic" %>

<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="~/UserControls/LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="~/UserControls/ImageThumbnail.ascx" %>

<script runat="server">
  Property ArticleID() As Integer
        Get
            Dim m_articleID As Integer
            Dim id As Object = ViewState("ArticleId")
            If Not id Is Nothing Then
                m_articleID = CInt(id)
            Else
                id = Request.QueryString("ArticleId")
                If Not id Is Nothing Then
                    m_articleID = CInt(id)
                Else
                    m_articleID = 1
                End If
                
                ViewState("ArticleId") = m_articleID
            End If
            Return m_articleID
        End Get
        Set(ByVal value As Integer)
            ViewState("ArticleId") = value
        End Set
    End Property
    
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Request("ArticleID") Is Nothing = True Then
            Response.Redirect("~/news/list.aspx")
        End If
        Dim NextID As String = ClubStarterKit.Web.News.NextArticle(ArticleID)
        Dim PrevID As String = ClubStarterKit.Web.News.PrevArticle(ArticleID)
        
        If Not NextID = "-" Then
            NextButton.NavigateUrl = "~/news/view.aspx?articleid=" & NextID
        Else
            NextButton.Enabled = False
        End If
            
        If Not PrevID = "-" Then
            PrevButton.NavigateUrl = "~/news/view.aspx?articleid=" & PrevID
        Else
            PrevButton.Enabled = False
        End If
    End Sub
    
    Protected Sub SqlDataSource2_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
        PhotoPanel.Visible = (e.AffectedRows <> 0)
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="body">
        <Club:LoginBanner ID="LoginBanner1" runat="server" />

        <div id="columnleft">
            <a name="content_start" id="content_start"></a>
            <div class="leftblock">
                <h2>
                    News Articles</h2>
                <Club:WebContent ID="WebContent1" runat="server" Section="news" />
            </div>
            <asp:ObjectDataSource ID="PhotoOBJDS" runat="server" SelectMethod="GetImages" TypeName="ClubStarterKit.Web.News">
                <SelectParameters>
                    <asp:QueryStringParameter Name="NewsID" QueryStringField="ArticleId" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:Panel ID="PhotoPanel" runat="server" CssClass="leftblock">
                <h2>Associated Album photos</h2>
                <asp:DataList ID="DataList2" runat="server" DataSourceID="PhotoOBJDS" RepeatColumns="2" CellSpacing="2" SelectedIndex="0" ItemStyle-CssClass="unselected">
                    <ItemTemplate>
                        <a href='../photo/contents.aspx?Albumid=<%#Eval("album") %>'>
                            <asp:Image ID="Image1" ImageUrl='<%# "~/UserControls/imagefetch.ashx?size=1&imageid=" & Cstr(Eval("id")) %>'
                                runat="server" /><br />
                            <asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" />
                        </a>
                    </ItemTemplate>
                </asp:DataList>
            </asp:Panel>
        </div>
        <!--
        
        Right column
        
        -->
        <div id="columnright">
            <div class="rightblock">
                <a href="list.aspx">News Article List</a></div>
            <div class="rightblock">
                <div class="dashedline">
                </div>
                <asp:ObjectDataSource ID="ArticleOBJDS" runat="server" SelectMethod="GetNewArticle" TypeName="ClubStarterKit.Web.News">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" Type="Int32" />
                    </SelectParameters>
                
                </asp:ObjectDataSource>
                <asp:FormView ID="FormView1" runat="server" DataSourceID="ArticleOBJDS" DataKeyNames="id"
                    Width="444px">
                    <ItemTemplate>
                        <h2>
                            <asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" />
                        </h2>
                        <div class="itemdetails">
                            <p>
                                <asp:Label Text='<%# Eval("itemdate","{0:D}") %>' runat="server" ID="itemdateLabel" />
                            </p>
                        </div>
                        <Club:ImageThumbnail ID="thumb1" runat="server" ImageSize="large" PhotoID='<%# Eval("photo") %>' />
                        <p>
                            <asp:Label Text='<%# Eval("description") %>' runat="server" ID="descriptionLabel" />
                        </p>
                        <p>
                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
                                DataSourceID="DownloadsOBJDS" GridLines="None" Width="409px">
                                <Columns>
                                    <asp:BoundField DataField="Title" Visible="False" HeaderText="Title" SortExpression="Title" />
                                    <asp:BoundField DataField="URL" Visible="False" HeaderText="URL" SortExpression="URL" />
                                    <asp:BoundField DataField="id" Visible="False" HeaderText="id" InsertVisible="False" ReadOnly="True"
                                        SortExpression="id" />
                                        <asp:TemplateField HeaderText="Downloads">
                                        <ItemTemplate>
                                <asp:HyperLink ID="HyperLink1" Text='<%# Eval("Title") %>' runat="server" NavigateUrl='<%# Eval("URL","~/Documents/{0}") %>' />
                            </ItemTemplate>
                            </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            &nbsp;</p>
                        <div class="downloadevent">
                            <a href='<%# "print.aspx?articleid=" & CStr(Eval("id")) %>' target="_blank">
                                <asp:Image ID="Image2" SkinID="print"  runat="server" />
                                </a><a href='<%# "print.aspx?articleid=" & CStr(Eval("id")) %>' target="_blank">Printer
                                        Friendly Version</a>
                        </div>
                        <asp:Panel runat="server" ID="panel1" CssClass="actionbuttons" Visible='<%# User.IsInRole("Administrators") %>'>
                            <Club:RolloverLink ID="editbtn" runat="server" Text="Edit Article" NavigateURL='<%# "edit.aspx?ArticleID=" & ArticleID%>' />
                            <Club:RolloverLink ID="HyperLink2" NavigateURL='<%# "~/News/Download.aspx?articleid=" & CStr(Request("Articleid")) %>' runat="server" Text="Downloads" />
                        </asp:Panel>
                    </ItemTemplate>
                </asp:FormView>
                <br />
                <asp:ObjectDataSource ID="DownloadsOBJDS" runat="server" SelectMethod="ArticleDownloads"
                    TypeName="ClubStarterKit.Web.News">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="id" QueryStringField="ArticleID" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                <div class="dashedline">
                </div>
                <div class="nextlink">
                    <asp:Hyperlink ID="NextButton" runat="server">Next ></asp:Hyperlink>
                </div>
                <asp:Hyperlink ID="PrevButton" runat="server">< Previous</asp:Hyperlink>
            </div>
        </div>
        <div class="clear2column">
        </div>
    </div>
</asp:Content>